<?php
defined('OA_LIB_PATH') || define('OA_LIB_PATH', '/opt/op/OALib');
defined('OPEN_LIB_PATH') || define('OPEN_LIB_PATH', '/opt/op/OpenLib');

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';
require_once OPEN_LIB_PATH . '/open/models/OaCodeModel.php';

class OaCodeModelTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_model;
    
    protected function setUp()
    {
        $logger = Log::factory('console', '', '', array(
            'lineFormat' => '[%1$s] [%3$s] %5$s(%6$s): %4$s',
            'timeFormat' => '%Y-%m-%d %H:%M:%S',
            'mode' => '0666'
        ), PEAR_LOG_DEBUG);
        $this->_logger = $logger;
        $this->_model = new OaCodeModel($logger);
    }
    
    protected function tearDown()
    {
        
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testAddCompany($id)
    {
//        $this->markTestSkipped();
        $result = $this->_model->addCompany($id, 'JAG13中文', 1, '', array(), 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testGetCompany($id)
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompany($id, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testGetCompanyByName($id)
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompanyByName('JAG13', OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    public function testGetCompanyList()
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompanyList(0, 10, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    public function testGetCompanyListCount()
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompanyListCount(OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testModifyCompany($id)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyCompany($id, array(
            'SP_NAME' => 'SNDA中文'
        ), OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testModifyCompanyId($id)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyCompanyId(77, $id, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider companyProvider
     */
    public function testDeleteCompany($id)
    {
        $this->markTestSkipped();
        $result = $this->_model->deleteCompany($id, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testAddApp($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->addApp($appId, 'JAG13中文', $companyId, 1, '', 
            array(), OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testGetApp($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getApp($appId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testGetAppByName($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getAppByName('JAG13中文', OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testGetAppList($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getAppList($companyId, 0, 5, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testGetAppListCount($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getAppListCount($companyId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testModifyApp($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyApp($appId, array(
        	'SERVICE_NAME' => 'JAG13中文'
        ), OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testModifyAppId($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyAppId(77, $appId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider appProvider
     */
    public function testDeleteApp($companyId, $appId)
    {
        $this->markTestSkipped();
        $result = $this->_model->deleteApp($appId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testAddArea($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->addArea($appId, $areaId, '一区', 1, '', array(), 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testGetArea($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getArea($appId, $areaId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testGetAreaList($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getAreaList($appId, 0, 5, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testGetAreaListCount($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getAreaListCount($appId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testModifyArea($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyArea($appId, $areaId, array(
            'AREA_NAME' => '一区'
        ), OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testModifyAreaCode($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyAreaCode($appId, $areaId, 2, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider areaProvider
     */
    public function testDeleteArea($companyId, $appId, $areaId)
    {
        $this->markTestSkipped();
        $result = $this->_model->deleteArea($appId, $areaId, OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testAddGroup($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->addGroup($appId, $areaId, $groupId, '一组', 1, '', array(), 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testGetGroup($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getGroup($appId, $areaId, $groupId, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testGetGroupList($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getGroupList($appId, $areaId, 0, 5, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testGetGroupListCount($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getGroupListCount($appId, $areaId, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testModifyGroup($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyGroup($appId, $areaId, $groupId, array(
            'GROUP_NAME' => '一组'
        ), OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testModifyGroupCode($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyGroupCode($appId, $areaId, $groupId, 2, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider groupProvider
     */
    public function testDeleteGroup($companyId, $appId, $areaId, $groupId)
    {
        $this->markTestSkipped();
        $result = $this->_model->deleteGroup($appId, $areaId, $groupId, 
            OaAppModel::APP_CONFIG_ENV_PRODUCTION);
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    public function testUnicode()
    {
//        $this->markTestSkipped();
//        $result = $this->_model->unicode(1, OaAppModel::APP_CONFIG_ENV_PRODUCTION, 
//            0, 1, -1, -1, '2010-01-01 00:00:00', '2010-12-31 00:00:00');
//        $this->_logger->info($result);
//        $result = $this->_model->unicode(1, OaAppModel::APP_CONFIG_ENV_PRODUCTION, 
//            0, -1, -1, -1);
//        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    public function companyProvider()
    {
        return array(
            array(1000004)
        );
    }
    
    public function appProvider()
    {
        return array(
            array(1000004, 110108100)
        );
    }
    
    public function areaProvider()
    {
        return array(
            array(1000004, 110108100, 1)
        );
    }
    
    public function groupProvider()
    {
        return array(
            array(1000004, 110108100, 1, 1)
        );
    }
}